<template>
	<view>
		<block v-if="is_captcha">
			<view class="" :style="customStyle">
				<u-form-item :label-position="labelPosition" label-width="150" label="验证码">
					<view class="u-m-r-15"><u-input v-model="captcha" /></view>
					<u-image slot="right" width="250rpx" height="60rpx" :src="img_url" @click="getCaptcha"></u-image>
				</u-form-item>
			</view>
		</block>
	</view>
</template>

<script>
export default {
	name: 'fa-captchaparts',
	props: {
		value: {
			type: String,
			default: ''
		},
		ident:{
			type:[String,Number],
			default:''
		},
		mode: {
			type: String,
			default: 'postquestion'
		},
		labelPosition: {
			type: String,
			default: 'top'
		},
		customStyle: {
			type: Object,
			default() {
				return {};
			}
		}
	},
	computed: {
		is_captcha() {
			return this.vuex_config.captchaparts && this.vuex_config.captchaparts.indexOf(this.mode) != -1;
		}
	},
	watch: {
		captcha(newValue, oldValue) {
			this.$emit('input', newValue);
		}
	},
	mounted() {
		this.getCaptcha()
	},
	data() {
		return {
			captcha: '',
			img_url:''
		};
	},
	methods:{
		getCaptcha(){
			this.$api.captcha({ident:this.ident}).then(res=>{
				if(res.code==1){
					this.img_url = res.data;
				}
			})
		}
	}
};
</script>

<style lang="scss"></style>
